/**
 *  防抖 
 * */
function debounce(func, delay) {
  let timer = null;
  return function (...args) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      func.apply(this, args)
    }, delay)
  }
}

// 测试用例
const debouncedFn = debounce(() => console.log('执行了'), 1000);
debouncedFn();
debouncedFn();
debouncedFn();